package com.wyclabs.auth.common.properties;

import com.wyclabs.auth.common.constants.GrantType;
import com.wyclabs.commons.constants.PlatFormType;
import lombok.Data;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 客户端相关配置
 * @author Wyccc
 * @date 2019/10/17
 */
@Data
public class ClientProperties {

    /**
     * 客户端id
     */
    private String clientId;

    /**
     * 客户端密钥
     */
    private String clientSecret;

    /**
     * 可访问范围,多个通过，分隔
     */
    private String scope = "all";

    /**
     * 平台类型
     */
    private PlatFormType platFormType;

    /**
     * 客户端支持的授权类型
     */
    private Set<String> grantTypeSet;


    public ClientProperties(String clientId, String clientSecret, String... grantTypes) {
        this(clientId, clientSecret);
        grantTypeSet.addAll(new HashSet<>(Arrays.asList(grantTypes)));
    }

    public ClientProperties(String clientId, String clientSecret) {
        this();
        this.clientSecret = clientSecret;
        this.clientId = clientId;
    }

    public ClientProperties() {
        //设置默认的grantType
        Set<String> grantTypes = new HashSet<>();
        grantTypes.add(GrantType.PASSWORD.getName());
        grantTypes.add(GrantType.REFRESH_TOKEN.getName());
        grantTypeSet = grantTypes;
    }
}
